<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>小海智途</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="" name="keywords">
    <meta content="" name="description">
    <!-- map -->
	<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <!-- Favicon -->
    <link href="img/logo.png" rel="icon">

    <!-- Google Web Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Heebo:wght@400;500;600;700&display=swap" rel="stylesheet">
    
    <!-- Icon Font Stylesheet -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css" rel="stylesheet">

    <!-- Libraries Stylesheet -->
    <link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
    <link href="lib/tempusdominus/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" />

    <!-- Customized Bootstrap Stylesheet -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Template Stylesheet -->
    <link href="css/style.css" rel="stylesheet">
    <style>
      
      #container {
        width: 100%;
        height: 93%;
      }
    </style>
  </head>
  <body>
  	<div class="container-fluid position-relative bg-white d-flex p-0">
        <!-- Spinner Start -->
        <div id="spinner" class="show bg-white position-fixed translate-middle w-100 vh-100 top-50 start-50 d-flex align-items-center justify-content-center">
            <div class="spinner-border text-primary" style="width: 3rem; height: 3rem;" role="status">
                <span class="sr-only">Loading...</span>
            </div>
        </div>
        <!-- Spinner End -->
  	
  	<!-- Sidebar Start -->
        <div th:replace="~{common :: #sidebar}"></div>
     <!-- Sidebar End -->
      <!-- Content Start -->
        <div class="content">
            <!-- Navbar Start -->
            <div th:replace="~{common :: #navbar}"></div>
            <!-- Navbar End -->

			<!-- Map End -->
			<div id="container" class="map"></div>
				<div class="input-card">
				    <h4>左击获取经纬度：</h4>
				    <div class="input-item">
				    	<input type="text" id="name" placeholder="输入坐标标记名">
					</div>
				    <div class="input-item">
				    	<input type="text" readonly="true" id="lnglat" placeholder="自动获取坐标点">
					</div>
					<div class="input-item">
                    	<button class="btn btn-primary w-100 m-2" type="button" id ="delete">删除坐标</button>                           
                    </div>
                    <div class="input-item">
                    	<button class="btn btn-primary w-100 m-2" type="button" id ="viewRoute">展示路线</button>                           
                    </div>
                    <div class="input-item">
                    	<button class="btn btn-primary w-100 m-2" type="button" id ="deleteRoute">删除路线</button>                           
                    </div>
                    <div class="input-item">
                    	<button class="btn btn-primary w-100 m-2" type="button" id ="addRoute">添加路线</button>                           
                    </div>				
				</div>
			<!-- Map End -->
            


            <!-- Footer Start -->
            <div th:replace="~{common :: #footer}"></div>
            <!-- Footer End -->
        </div>
        <!-- Content End -->
     
    	
    </div>

    <!-- JavaScript Libraries -->
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="lib/chart/chart.min.js"></script>
    <script src="lib/easing/easing.min.js"></script>
    <script src="lib/waypoints/waypoints.min.js"></script>
    <script src="lib/owlcarousel/owl.carousel.min.js"></script>
    <script src="lib/tempusdominus/js/moment.min.js"></script>
    <script src="lib/tempusdominus/js/moment-timezone.min.js"></script>
    <script src="lib/tempusdominus/js/tempusdominus-bootstrap-4.min.js"></script>

    <!-- Template Javascript -->
    <script src="js/main.js"></script>
  </body>
</html>



<script type="text/javascript">
  window._AMapSecurityConfig = {
    securityJsCode: "db12ca9a2c46a35ea76b279a1948e7b1",
  };
</script>
<script src="https://webapi.amap.com/loader.js"></script>
<script type="text/javascript">
  var arr = new Array(); //经纬度坐标数组
  var dragRouteList = new Array();
  var textList = new Array();
  AMapLoader.load({
    key: "8e91d38f528dddb1863594bf39843cae", //申请好的Web端开发者 Key，调用 load 时必填
    version: "2.0", //指定要加载的 JS API 的版本，缺省时默认为 1.4.15
    plugins: [ "AMap.Scale","AMap.DragRoute"]
  })
    .then((AMap) => {
      const map = new AMap.Map("container",{
    	  center : [110.509674,19.981246]
      });
      
      var scale = new AMap.Scale();
      map.addControl(scale);
      var name = "坐标点";
      map.on('click', function(e) {
          document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
          if(document.getElementById("name").value==""){
        	  name = "坐标点";
          }else{name = document.getElementById("name").value}
          
          var text = new AMap.Text({
              text: name,
              anchor:'center', // 设置文本标记锚点
              draggable:true,
              cursor:'pointer',
              angle:0,
              style:{
                  'padding': '.75rem 1.25rem',    
                  'background-color': 'white',
                  'width': '16rem',
                  'border-width': 0,
                  'box-shadow': '0 2px 6px 0 rgba(114, 124, 245, .5)',
                  'text-align': 'center',
                  'font-size': '15px',
                  'color': 'black'
              },
              position: [e.lnglat.getLng(),e.lnglat.getLat()]
          });
          text.setMap(map);
          textList.push(text);
          arr.push(new AMap.LngLat(e.lnglat.getLng(),e.lnglat.getLat()));
      });
      document.getElementById("delete").onclick = function(){
    	  var dtext = textList.pop();
    	  dtext.remove();
    	  arr.pop();
      }
      var dragRoute;
      document.getElementById("viewRoute").onclick = function(){
    	  dragRoute = new AMap.DragRoute(map, arr, AMap.DrivingPolicy.LEAST_FEE);
          dragRoute.search(); //查询导航路径并开启拖拽导航
          dragRouteList.push(dragRoute);
      }
      document.getElementById("deleteRoute").onclick = function(){
    	  while(dragRouteList.length>0)
    	  { 
    		  var ddragRoute = dragRouteList.pop();
    		  dragRoute.destroy();
    	  }
    	  arr = [];
    	  while(textList.length>0)
    	  { 
    		  var dtext = textList.pop();
        	  dtext.remove();
    	  }
      }
    })
    .catch((e) => {
      console.error(e); //加载错误提示
    });
</script>